package com.niiwoo.civet.trade.service.local.newRefund.notify;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.lycheepay.gateway.client.BizException;
import com.niiwoo.civet.trade.service.local.newRefund.notify.enums.RefundNotifyEnum;

@Component
public class RefundNotifyFactory {
	
	@Autowired
	private List<RefundNotifyHandle> refundNotifyList;
	
    /**
     * 根据枚举类型获取对应的处理类
     * 
     * @param refundNotifyEnum
     * @return
     */
	public RefundNotifyHandle create(RefundNotifyEnum refundNotifyEnum) {
		RefundNotifyHandle targetRefundNotify = null;
		for (RefundNotifyHandle refundNotify : refundNotifyList) {
			if (refundNotify.getType().equals(refundNotifyEnum)) {
				targetRefundNotify = refundNotify;
			}
		}
		if (null == targetRefundNotify) {
			throw new BizException("", "暂不支持该类型的消息处理，" + refundNotifyEnum.getDesc());
		}
		return targetRefundNotify;
	}
}